package com.vanke.kotlin_mvp

import org.jetbrains.anko.db.MapRowParser
import org.jetbrains.anko.db.SelectQueryBuilder

/**
 * @name Kotlin_MVP
 * @package name：com.vanke.kotlin_mvp
 * @class describe
 * @anthor shiyuchuan
 * @time 2017/8/17 13:43
 */
fun <T : Any> SelectQueryBuilder.parseList(parser: (Map<String, Any?>) -> T): List<T>
        = parseList(object : MapRowParser<T> {
    override fun parseRow(columns: Map<String, Any?>): T = parser(columns)
})

fun <T : Any> SelectQueryBuilder.parseOpt(parser: (Map<String, Any?>) -> T): T?
        = parseOpt(object : MapRowParser<T> {
    override fun parseRow(columns: Map<String, Any?>): T = parser(columns)
})

fun <K, V : Any> MutableMap<K, V?>.toVarargArray(): Array<out Pair<K, V>>
        = map({ Pair(it.key, it.value!!) }).toTypedArray()